package com.ftg.learn.chapter06;

import com.ftg.learn.chapter05.ItemList;

import javax.xml.bind.SchemaOutputResolver;

/**
 * @author kangjx
 * @createTime 2022/7/4
 */
public class MyStackImple<T> implements  MyStack<T>{

    ItemList<T> list;

    public MyStackImple(){
        list = new ItemList<>();
    }

    @Override
    public int size() {
        return list.size();
    }

    @Override
    public void push(T t1) {
        list.add(t1);
    }

    @Override
    public T pop() {
        T t1 = list.getTailVal();
        list.deleteTail();
        return t1;
    }

    @Override
    public T poll() {
        return list.getTailVal();
    }

    public static void main(String[] args) {
        MyStack<Integer> myStack = new MyStackImple<>();
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);
        myStack.push(5);
        myStack.push(6);
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
        myStack.push(7);
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
        myStack.push(9);
        System.out.println(myStack.pop());
    }

}
